#include "Network.h"
#include "DebugUtil.h"

void Network::init()
{
	mNetInit.netLibInit();
}

void Network::connectServer(const char* addr, unsigned short port)
{
	SOCKET sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	if(INVALID_SOCKET == sock)
	{
		PR("create socket error:[%d]\n",WSAGetLastError());
		assert(!"got an error while creating socket\n");
		return;
	}
	sockaddr_in srvAddr={0};
	srvAddr.sin_family = AF_INET;
	srvAddr.sin_addr.s_addr = inet_addr(addr);
	srvAddr.sin_port = htons(port);
	if(SOCKET_ERROR==::connect(sock,(sockaddr*)(&srvAddr),sizeof(srvAddr)))
	{
		int err = WSAGetLastError();
		PR("connect to server error:[%d]\n",err);
		//assert(!"connect error");
		return;
	}
}

void Network::onReceiveMessage(const MsgHeader* pMsg)
{
	switch(pMsg->msgType)
	{
	case Msg_C2s_Login::MsgType:
		break;
	default:
		assert(0&&"msg error");
	}
}

void Network::end()
{
	//delete sysElement from game application
}